<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
          position: relative;
        width: 300px;
        border-bottom:1px solid #ccc;
        margin: 100px auto;
      }
      .box input {
          width: 270px;
          height: 30px;
          border: 0;
          outline: none;
      }
      .box img {
          position: absolute;
          width: 24px;
          top: 2px;
          right: 2px;
      }

    </style>
  </head>
  <body>
    <div class="box">
      <label for="">
        <img src="./images/close.png" alt="" class="eye"/>
      </label>
      <input type="password" name="" id="pwd" />
    </div>

    <script>
        var eye = document.querySelector('.eye')
        var input = document.querySelector('#pwd')
        // console.log(eye);
        var flag = true
        eye.onclick = function() {
              if (flag) {
                  pwd.type = 'text'
                  eye.src = './images/open.png'
                  flag = false
              } else {
                  pwd.type = 'password'
                  eye.src = './images/close.png'
                  flag = true
              }
        }
    </script>
  </body>
</html>
